package com.it.server.controller.user;


import com.it.common.result.Result;
import com.it.pojo.Entity.Address;
import com.it.server.service.IAddressService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2025-07-23
 */
@RestController("userAddressController")
@RequestMapping("/user/address")
@Tag(name = "用户地址接口")
@Slf4j
public class AddressController {
    @Autowired
    IAddressService addressService;

    @GetMapping("/list")
    @Operation(summary="查询用户地址列表")
    public Result<List<Address>> list() {
        log.info("查询用户地址列表");
        List<Address> list = addressService.list();
        return Result.success(list);
    }
    @GetMapping("/detail/{id}")
    @Operation(summary="查询用户地址详情")
    public Result<Address> detail(@PathVariable Integer id) {
        log.info("查询用户地址详情");
        Address address = addressService.getById(id);
        return Result.success(address);
    }
    @GetMapping("/delete/{id}")
    @Operation(summary="删除用户地址")
    public Result<String> delete(@PathVariable Integer id) {
        log.info("删除用户地址");
        addressService.removeById(id);
        return Result.success("删除成功");
    }
    @PostMapping("/update")
    @Operation(summary="修改用户地址")
    public Result<String> update(@RequestBody Address address) {
        log.info("更新用户地址");
        addressService.updateById(address);
        return Result.success("更新成功");
    }
    @PutMapping("/add")
    @Operation(summary="添加用户地址")
    public Result<String> add(@RequestBody Address address) {
        log.info("添加用户地址");
        addressService.save(address);
        return Result.success("添加成功");
    }
    @PostMapping("/setDefault")
    @Operation(summary="设置默认地址")
    public Result<String> setDefault(@PathVariable Integer id) {
        addressService.setDefault(id);
        return Result.success("设置成功");
    }
}
